package com.zyx.xunyilu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zyx.xunyilu.entity.Version;
import com.zyx.xunyilu.mapper.VersionMapper;
import com.zyx.xunyilu.utils.RestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @ClassName: VersionController
 * @author: zyx
 * @E-mail: 1377631190@qq.com
 * @DATE: 2019/11/17 16:02
 */
@CrossOrigin
@RestController
@RequestMapping("/app")
public class VersionController {

    @Autowired
    VersionMapper versionMapper;

    @PostMapping("/upload")
    public RestResponse uploadApp(@RequestParam("version") String version,
                                  @RequestParam("name") String name) {
        Version last = versionMapper.selectList(new QueryWrapper<Version>().orderByDesc("id")).get(0);
        String appVersion = last.getAppVersion();
        HashMap<String, String> payload = new HashMap<>();
        if (appVersion.equals(version)) {
            payload.put("update", "false");
            return RestResponse.ok(payload);
        }
        payload.put("info", last.getContent());
        payload.put("update", "true");
        payload.put("url", last.getUrl());
        return RestResponse.ok(payload);
    }

}
